package com.thiswhyme.demo.msgpush.core.event;

import com.thiswhyme.demo.msgpush.core.event.bean.EventType;
import com.thiswhyme.demo.msgpush.core.event.bean.WebSocketEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @description: WebSocket连接关闭事件处理器
 * @author: thiswhyme
 * @date: 2021/9/28
 */
@Slf4j
public abstract class AbstractCloseEventWsHandler implements EventHandler {

    @Override
    public EventType supportType() {
        return EventType.COLSE;
    }

    @Override
    public void handle(WebSocketEvent event) {
        List<String> identifiers = event.getIdentifiers();
        log.debug("【ws连接关闭事件】处理，目标：{}", identifiers);
        if (CollectionUtils.isEmpty(identifiers)) {
            return;
        }

        doHandle(event);
    }

    /**
     * ws连接关闭事件处理
     * @param event
     */
    public abstract void doHandle(WebSocketEvent event);
}
